﻿

@model string
@{
    ViewBag.Title = "订单列表";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    string date = "";
    long uid = 0;
    if (ViewBag.date != null)
    {
        date = (string)ViewBag.date;
    }
    if (ViewBag.uid != null)
    {
        uid = (long)ViewBag.uid;
    }
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();

    DateTime beg = Convert.ToDateTime(date);
    DateTime end = Convert.ToDateTime(date).AddDays(1);
    //条件筛选
    var queryable_buyer = (from t in dbcontext.ADZ_OrderSettlement.Where(t => t.create_time >= beg && t.create_time < end && t.uid == uid && t.buyer_money > 0)
                           join u in dbcontext.View_Order
                                on t.order_id equals u.order_id
                           orderby t.seq_id descending
                           select new
                           {
                               order = u,
                               money = t.buyer_money
                           }
                            ).ToList();

    var queryable_recommend = (from t in dbcontext.ADZ_OrderSettlement.Where(t => t.create_time >= beg && t.create_time < end && t.recommend_uid == uid && t.recommend_money > 0)
                               join u in dbcontext.View_Order
                                    on t.order_id equals u.order_id
                               orderby t.seq_id descending
                               select new
                               {
                                   order = u,
                                   money = t.recommend_money
                               }
                   ).ToList();

}

<p>
    <br />
</p>
<button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
<p>
    <br />
</p>
<h5>下单返利列表</h5>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th>返利金额</th>
            <th>订单号</th>
            <th>买家手机号</th>
            <th>订单金额</th>
            <th>订单状态</th>
            <th>下单时间</th>
            @*<th>是否支付</th>*@
            <th>支付类型</th>
            <th>支付时间</th>
            <th>关闭支付时间</th>
            <th>是否发货</th>
            <th>是否申请退款</th>
            <th>收货人</th>
            <th>发票信息</th>
            <th>操作</th>
        </tr>
    </thead>
    @if (queryable_buyer != null && queryable_buyer.Count != 0)
    {
        int index = 0;
        foreach (var item in queryable_buyer)
        {
            var m = item.order;
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>@item.money</td>
                <td>@m.order_NO</td>
                <td>@m.account_mobile</td>
                <td>@m.total_money</td>
                <td>
                    @{
                        int order_status = ConvertHelper.ConvertTo<int>(m.order_status, 0);
                        switch (order_status)
                        {
                            case (int)OrderStatus.WaitPay:
                                @:<div>@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.PaySucc:
                                @:<div class="blue">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.Complete:
                                @:<div class="green">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.Cancel:
                                @:<div class="gray">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                        }
                    }
                </td>
                <td>@m.create_time.ToString(1)</td>
                <td>
                    @if (m.pay_type.HasValue)
                    {
                        <div>@(MyEnumHelper.GetEnumItemDescription<PayType>(ConvertHelper.ConvertTo<int>(m.pay_type, 1)))</div>
                    }
                </td>
                <td>@m.pay_succ_time.ToString(1)</td>
                <td>
                    @{
                        if (m.order_source.Value == (int)OrderSource.UserCreate
                            && m.is_succ.Value == (int)PaySucc.NotPay)
                        {
                            <div>@m.pay_end_time.ToString(1)</div>
                        }
                    }
                </td>
                <td>
                    @switch (m.is_send.Value)
                    {
                        case (int)IsSend.NotSend:
                            @:<div>@(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))</div>
                            break;
                        case (int)IsSend.Sended:
                            <div class="green">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))
                                <br />@m.send_time.ToString()
                            </div>
                            break;
                        case (int)IsSend.GetUseSelf:
                            <div class="orange">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))
                                <br />@m.send_time.ToString()
                            </div>
                            break;
                    }
                </td>
                <td>
                    @if (!m.is_apply_refund.HasValue)
                    {
                        m.is_apply_refund = 0;
                    }
                    @switch (m.is_apply_refund.Value)
                    {
                        case (int)IsApplyRefund.NotApply:
                            @:<div>@(MyEnumHelper.GetEnumItemDescription<IsApplyRefund>(m.is_apply_refund.Value))</div>
                            break;
                        case (int)IsApplyRefund.AlreadyApply:
                            <div class="green">
                                @(MyEnumHelper.GetEnumItemDescription<IsApplyRefund>(m.is_apply_refund.Value))


                            </div>
                            break;
                    }
                </td>
                <td>@m.receiver [@m.receiver_telephone]</td>
                <td>
                    @switch (m.is_invoice)
                    {
                        case 0:
                            @:<div>不需要发票</div>
                            break;
                        case 1:
                            if (string.IsNullOrWhiteSpace(m.invoice_img))
                            {
                                <div class="red">发票资料未上传<br /> @m.invoice_title</div>
                            }
                            else
                            {
                                if (m.is_ready == 1)
                                {
                                    <div class="green">发票已开<br /> @m.invoice_title</div>
                                }
                                else
                                {
                                    <div class="red">发票未开<br /> @m.invoice_title</div>
                                }
                            }
                            break;
                    }
                </td>
                <td>
                    <a href="@Url.Action("OrderMasterInfo", "OrderMaster", new { id = m.order_id})" class="openbasetab">查看详情</a>
                </td>
            </tr>
        }
        <tr>
            <td colspan="20"></td>
        </tr>
    }
</table>
<div class="inline pull-left total">
    总行数：@queryable_buyer.Count
</div>

<p>
    <br />
    <hr />
</p>
<h5>推荐返利列表</h5>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th>返利金额</th>
            <th>订单号</th>
            <th>买家手机号</th>
            <th>订单金额</th>
            <th>订单状态</th>
            <th>下单时间</th>
            @*<th>是否支付</th>*@
            <th>支付类型</th>
            <th>支付时间</th>
            <th>关闭支付时间</th>
            <th>是否发货</th>
            <th>是否申请退款</th>
            <th>收货人</th>
            <th>发票信息</th>
            <th>操作</th>
        </tr>
    </thead>
    @if (queryable_recommend != null && queryable_recommend.Count != 0)
    {
        int index = 0;
        foreach (var item in queryable_recommend)
        {
            var m = item.order;
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>@item.money</td>
                <td>@m.order_NO</td>
                <td>@m.account_mobile</td>
                <td>@m.total_money</td>
                <td>
                    @{
                        int order_status = ConvertHelper.ConvertTo<int>(m.order_status, 0);
                        switch (order_status)
                        {
                            case (int)OrderStatus.WaitPay:
                                @:<div>@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.PaySucc:
                                @:<div class="blue">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.Complete:
                                @:<div class="green">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.Cancel:
                                @:<div class="gray">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                        }
                    }
                </td>
                <td>@m.create_time.ToString(1)</td>
                <td>
                    @if (m.pay_type.HasValue)
                    {
                        <div>@(MyEnumHelper.GetEnumItemDescription<PayType>(ConvertHelper.ConvertTo<int>(m.pay_type, 1)))</div>
                    }
                </td>
                <td>@m.pay_succ_time.ToString(1)</td>
                <td>
                    @{
                        if (m.order_source.Value == (int)OrderSource.UserCreate
                            && m.is_succ.Value == (int)PaySucc.NotPay)
                        {
                            <div>@m.pay_end_time.ToString(1)</div>
                        }
                    }
                </td>
                <td>
                    @switch (m.is_send.Value)
                    {
                        case (int)IsSend.NotSend:
                            @:<div>@(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))</div>
                            break;
                        case (int)IsSend.Sended:
                            <div class="green">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))
                                <br />@m.send_time.ToString()
                            </div>
                            break;
                        case (int)IsSend.GetUseSelf:
                            <div class="orange">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))
                                <br />@m.send_time.ToString()
                            </div>
                            break;
                    }
                </td>
                <td>
                    @if (!m.is_apply_refund.HasValue)
                    {
                        m.is_apply_refund = 0;
                    }
                    @switch (m.is_apply_refund.Value)
                    {
                        case (int)IsApplyRefund.NotApply:
                            @:<div>@(MyEnumHelper.GetEnumItemDescription<IsApplyRefund>(m.is_apply_refund.Value))</div>
                            break;
                        case (int)IsApplyRefund.AlreadyApply:
                            <div class="green">
                                @(MyEnumHelper.GetEnumItemDescription<IsApplyRefund>(m.is_apply_refund.Value))


                            </div>
                            break;
                    }
                </td>
                <td>@m.receiver [@m.receiver_telephone]</td>
                <td>
                    @switch (m.is_invoice)
                    {
                        case 0:
                            @:<div>不需要发票</div>
                            break;
                        case 1:
                            if (string.IsNullOrWhiteSpace(m.invoice_img))
                            {
                                <div class="red">发票资料未上传<br /> @m.invoice_title</div>
                            }
                            else
                            {
                                if (m.is_ready == 1)
                                {
                                    <div class="green">发票已开<br /> @m.invoice_title</div>
                                }
                                else
                                {
                                    <div class="red">发票未开<br /> @m.invoice_title</div>
                                }
                            }
                            break;
                    }
                </td>
                <td>
                    <a href="@Url.Action("OrderMasterInfo", "OrderMaster", new { id = m.order_id})" class="openbasetab">查看详情</a>
                </td>
            </tr>
        }
        <tr>
            <td colspan="20"></td>
        </tr>
    }
</table>
<div class="inline pull-left total">
    总行数：@queryable_recommend.Count
</div>